package com.nchu.ft.controller;


import com.nchu.ft.common.domain.ApiResult;
import com.nchu.ft.entity.Genealogy;
import com.nchu.ft.service.GenealogyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: GenealogyController
 * @description:
 * @Author: Chuanwei Li
 * @CreateTime: 2025-08-17 15:55
 * @Version: 1.0
 */
@RestController
@RequestMapping("/genealogy")
public class GenealogyController {

    @Autowired
    private GenealogyService<Genealogy> genealogyService;

    @PostMapping("/addGenealogy")
    public ApiResult<Boolean> addGenealogy(Genealogy genealogy) {
        return ApiResult.success(genealogyService.save(genealogy));
    }

    @PostMapping("/updateGenealogy")
    public ApiResult<Boolean> updateGenealogy(Genealogy genealogy) {
        return ApiResult.success(genealogyService.updateById(genealogy));
    }

    @PostMapping("/deleteGenealogy")
    public ApiResult<Boolean> deleteGenealogy(Integer id) {
        return ApiResult.success(genealogyService.removeById(id));
    }

    @GetMapping("/getGenealogyById")
    public ApiResult<Genealogy> getGenealogy(@RequestParam("genealogyId") Integer genealogyId) {
        return ApiResult.success(genealogyService.getById(genealogyId));
    }

    @GetMapping("/getGenealogyList")
    public ApiResult<List<Genealogy>> getGenealogyList() {
        return ApiResult.success(genealogyService.list());
    }
}
